package com.job.sun.HomeWork0720;

import java.rmi.MarshalledObject;
import java.security.Key;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

/**
 * @author 张春阳
 * @version 1.0
 * @since 2022-07-20 21:26:38
 * Your local changes would be overwritten by merge. Commit, stash or revert them to proceed.
 */
public class HomeWork {
    public static void main(String[] args) {
        //Map<K,V> 作业: 键盘任意输入一个字符串,求这个字符串里 字母及其出现次数. 按照出现顺序打印.
        // LinkedHashMap
        Map<Character,Integer> map =new LinkedHashMap<>();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入任意字符串");
        String next = sc.next();
        execute(next, map);
        Set<Character> characters = map.keySet();
        for (Character character : characters) {
            System.out.println(character+"~~~"+map.get(character));
        }

    }
private static void execute(String next ,Map<Character,Integer> map) {
    char[] chars = next.toCharArray();
    for (char aChar : chars) {
        if (Character.isUpperCase(aChar)) {
            if (!map.containsKey(aChar)) {

                map.put(aChar, 1);
            } else {
                Integer integer = map.get(aChar);
                integer++;
                map.put(aChar, integer);
            }
        }
    }


}
}